<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>登录</title>
    <!-- 样 式 文 件 -->
    <link rel="stylesheet" href="__LIB__/pear/css/pear.css"/>
    <link rel="stylesheet" href="__STATIC_ADMIN__/css/other/login.css"/>
</head>
<!-- 代 码 结 构 -->
<body background="__STATIC_ADMIN__/images/background.svg" style="{:hook('adminLoginStyle')}">

<form class="layui-form" action="javascript:void(0);">
    <div class="layui-form-item">
        <img class="logo" src="__STATIC_ADMIN__/images/logo.png"/>
        <div class="title">站点后台管理系统</div>
        <div class="desc">
            Management System
        </div>
    </div>
    <div class="layui-form-item input-login">
        <input name="username" placeholder="请输入用户名" lay-verify="required" hover class="layui-input"/>
        <div class="input-group-append">
            <div class="input-group-text">
                <i class="layui-icon layui-icon-username"></i>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <input type="password" name="password" placeholder="请输入密码" lay-verify="required" hover
               class="layui-input"/>
        <div class="input-group-append">
            <div class="input-group-text">
                <i class="layui-icon layui-icon-password"></i>
            </div>
        </div>
    </div>
    <input type="hidden" name="__token__" value="{:token()}" />
    {if $login_captcha ==1}
    <div class="layui-form-item">
        <input id="captcha" name="captcha" placeholder="请输入验证码" hover lay-verify="required"
               class="code layui-input layui-input-inline" style="width:160px;"/>
        <img src="{:url('login/captcha')}" onclick="changeCaptcha()" class="codeImage" id="codeImage"/>
    </div>
    {/if}

    <!--<div class="layui-form-item">
        <input type="checkbox" name="" title="记住密码" lay-skin="primary" checked>
    </div>-->
    <div class="layui-form-item">
        <button class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
            立即登录
        </button>
    </div>
</form>
<!-- 资 源 引 入 -->
<script src="__LIB__/layui/layui.js"></script>
<script src="__LIB__/pear/pear.js"></script>
{:hook('indexFooter')}
<script>
  //删除本地sessionStrorage数据
  sessionStorage.clear();

  function changeCaptcha() {
    if ("{$login_captcha}" == 1) {
      document.getElementById('captcha').value = '';
      document.getElementById('codeImage').src = "{:url('login/captcha')}?" + Math.random();
    }
  }

  layui.use(['form', 'button', 'popup', 'jquery'], function () {
    var form = layui.form;
    var button = layui.button;
    var popup = layui.popup;
    var $ = layui.jquery;
    var layer = layui.layer;

    // 登录过期的时候，跳出ifram框架
    if (top.location != self.location) top.location = self.location;

    form.on('submit(login)', function (data) {
      // 登录逻辑
      data = data.field;
      $.post("{:url('admin/login/checkLogin')}", {
        username: data.username,
        password: data.password,
        captcha: data.captcha,
        __token__:data.__token__
      }, function (res) {
        if (res.code) {
          button.load({
            elem: '.login',
            time: 1000,
            done: function () {
              popup.success("登录成功", function () {
                location.href = "{:url('admin/index/index')}"
              });
            }
          })
        } else {
          changeCaptcha();
          layer.msg(res.msg, {time: 2000, icon: 2})
        }
      })
      return false;
    });
  })
</script>
</body>
</html>
